package fr.epsi.activities.tache;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.TextView;
import com.example.MyLittleHotel.R;
import fr.epsi.BDD.BDD;

import java.sql.SQLException;

/**
 * Created by Florent Baudon on 02/06/2014.
 */
public class FicheTacheActivity extends Activity {

    TextView nomTache, emp, service, debut, fin;
    Cursor infoTache;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fichetachelayout);

        nomTache = (TextView)findViewById(R.id.ficheTacheMotif);
        emp = (TextView)findViewById(R.id.ficheTacheEmp);
        service = (TextView)findViewById(R.id.ficheTacheService);
        debut = (TextView)findViewById(R.id.ficheTacheDeb);
        fin = (TextView)findViewById(R.id.ficheTacheFin);

        Bundle b = this.getIntent().getExtras();

        nomTache.setText(b.getString("nomTache"));

        try{
            BDD bdd = new BDD();
            bdd.open(this);
            infoTache = bdd.getTacheNom(b.getString("nomTache"));
        }catch (SQLException e){
            e.printStackTrace();
        }
        if(infoTache!=null && infoTache.moveToFirst()) {
            service.setText(infoTache.getString(2));
            emp.setText(infoTache.getString(3) + " " + infoTache.getString(4));
            debut.setText(infoTache.getString(5));
            fin.setText(infoTache.getString(6));
        }
    }
}